<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Log in|Blog</title>

    <script type="text/javascript" src="../public/js/jquery-2.1.1.min.js"></script>
    <script src="../public/js/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="../public/js/jquery-cookie/jquery.cookie.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../public/js/jquery-easyui/themes/default/easyui.css" type="text/css"></link>
    <link rel="stylesheet" href="../public/js/jquery-easyui/themes/icon.css" type="text/css"></link>

    <link href="../public/css/login.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript">
        /**
         * 页面初始载入
         */
        $(document).ready(function () {
            /**
             * 讲本地cookies放置输入框
             */
            if ($.cookie("rmbUser") == "true") {
                $("#signup_check").attr("checked", true);
                $("#signup_email").val($.cookie("username"));
                $("#signup_password").val($.cookie("password"));
            }
        });

        /**
         * 提交按钮事件
         */
		$(function(){
			$("button").click(function(){
			if($("#signup_email").val()==""||$("#signup_password").val()=="")
			{
				$.messager.alert('警告','账号和密码不能为空!');
				 
			}
			else
			{
                var email = $("#signup_email").val();
                var password = $("#signup_password").val();
                /**
                 * ajax向接口传参，并处理
                 */
                $.ajax({
                    async: false,
                    type: "POST",
                    url:"/users/check_login",
                    data:{
                        email: email,
                        password: password
                    },
                    dataType: "text",
                    success: function (result) { //result为返回结果
                        if (result=="true"){

                            if ($("#signup_check").is(":checked")) {
                                //console.log($("#signup_check").is(":checked"));

                                if ($("#signup_check").is(":checked")) {
                                    var str_email = $("#signup_email").val();
                                    var str_password = $("#signup_password").val();
                                    $.cookie("rmbUser", "true", {expires: 7});
                                    $.cookie("username", str_email, {expires: 7});
                                    $.cookie("password", str_password, {expires: 7});
                                }
                                else {
                                    $.cookie("rmbUser", "false", {expire: -1});
                                    $.cookie("username", "", {expires: -1});
                                    $.cookie("password", "", {expires: -1});
                                }

                            }
                            //验证成功重定向到其他页面
                            window.location.href="register";

                        }
                        else{
                            alert("账号或密码错误,请重新输入！");
                        }


                    },
                    error: function () {
                    }
                })

			}
		});
	});
    </script>
</head>
<body>
    <div id="login_bg" class ="login_bg" style="background-image:url(../public/images/u3.jpg);"></div>
    <div class="login_header">
    	<span></span>
    </div>
    
    <div class="container">
    	<div class="form_header">
        	<h1 id="logo">Blog</h1>
			<h2 id="subheading">To explore and discover</h2>
        </div>
        <div class="signup_forms">
            	<div id="signup_forms_container" class="signup_forms_container">
                    	<form class="signup_form_form" id="sign_form" >
                        	<div class="signup_account" id="signup_account">
                            	<div class="form_user">	
        							<input type="text" name="email" placeholder="Email" id="signup_email" />
                                </div>
                                <div class="form_password">
           							<input type="password" name="password" placeholder="Password" id="signup_password"/>
        						</div>
                                <div class="form_remeber">
                                    <input name="sex" type="checkbox" id="signup_check"/><label for="signup_check">自动登录</label>
                                </div>
                            </div>
                            <div>
               					 <button type="button" id="signup_forms_submit"><span><strong>Log in</strong></span></button>
            				</div>
                        </form> 
                  		   
    			</div>
    	</div>
    </div>
    <div class="footer">
    	<div class="footer_signup_link">
        	<a class="signup_link" href="register.html">Sign up</a>
            <a href="https://www.baidu.com" target="_blank" class="link unnamed_1">Patent</a>
            <a href="#" target="_blank" class="link unnamed_2">About</a>
        </div>
        <div class="design_show">
        	<div class="designer_info">
            	<a href="#">Designed by Class 2 Software 11 <strong>Ray</strong></a>
                <a href="#" target="_blank" class="face"><img id="face" src="../public/images/face.jpg" alt="designed by RayZhang"/></a>
            </div>
        </div>
    </div>
</body>
</html>